<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			<h3>小黑的书架</h3>
			<ul>
				<li v-for="(item,index) in booksList" :key="item.id">
					<span>{{item.name}}-{{item.author}}</span>
					<!-- 注册点击事件 -->
					<button @click="del(item.id)">删除</button>
				</li>
			</ul>
		</div>
		
		<script src="js/vue.js"></script>
		<script>
			const app = new Vue({
				el:'#app',
				data:{
					booksList:[
						{id:1,name:'《红楼梦》',author:'曹雪芹'},
						{id:2,name:'《西游记》',author:'吴承恩'},
						{id:3,name:'《水浒传》',author:'施耐庵'},
						{id:4,name:'《三国演义》',author:'罗贯中'},
					]
				},
				methods:{
					del(id){
						//通过id进行删除数组中的对应项， 用filter
						//根据filter根据条件，保留满足条件的对应项，得到一个新数组
						this.booksList = this.booksList.filter(item => item.id !== id)
					}
				}
			})
		</script>
	</body>
</html>